use serde::Deserialize;
use serde::Serialize;
use ts_rs::TS;
use yata::core::PeriodType;
use yata::core::ValueType;

use super::IndicatorActionWrap;

///
/// Struct to hold the results of Struct yata::indicators::CommodityChannelIndex Commodity Channel Index CCI
///
/// yata::indicators::CommodityChannelIndex
///
///  参见[CCI](https://en.wikipedia.org/wiki/Commodity_channel_index)
///
#[derive(Serialize, Deserialize, Default, Debug, TS, Clone)]
#[ts(export)]
pub struct CCI {
    /// 1 signal
    /// When oscillator value goes above zone, then returns full sell signal.
    /// When oscillator value goes below -zone, then returns full buy signal.
    /// Otherwise no signal
    pub signal0: Option<IndicatorActionWrap>,

    /// 1 value
    ///oscillator value. Most of the time value is in the range around [-1.0; +1.0]
    ///Range in (-inf; +inf)
    pub oscillator: ValueType,
}

/// Configuration Commodity Channel Index
#[derive(Serialize, Deserialize, Debug, TS, Clone, Copy)]
#[ts(export)]
pub struct CCIConfig {
    /// period: PeriodType
    /// Main period size. Default is 18.
    ///
    /// Range in [2; PeriodType::MAX).
    pub period: PeriodType,

    /// zone: ValueType
    /// Signal zone size. Default is 1.0.
    ///
    /// Range in [0.0; +inf).
    pub zone: ValueType,
    //source: Source
    //Source type. Default is Close.
}

impl Default for CCIConfig {
    fn default() -> Self {
        Self {
            period: 18,
            zone: 1.0,
        }
    }
}
